package com.huangguolin.cloud.mybatis.flexigrid;

import com.huangguolin.cloud.mybatis.annotation.Colums;
import com.huangguolin.cloud.mybatis.entity.PtFileEntity;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Collection;

public class PagingEntity implements Serializable {

    /**
     * 当前页面
     */
    private Integer page = null;

    /**
     * 容量
     */
    private Integer rp = null;

    /**
     * 数据的开始
     */
    private Integer start = null;

    /**
     * 排序 asc
     */
    private String sortorder = null;

    /**
     * 按某个字段来排序
     */
    private String sortname = null;


    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getRp() {
        return rp;
    }

    public void setRp(Integer rp) {
        this.rp = rp;
    }

    public Integer getStart() {
        return (page-1)*rp;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public String getSortorder() {
        return sortorder;
    }

    public void setSortorder(String sortorder) {
        this.sortorder = sortorder;
    }

    public String getSortname() {
        return sortname;
    }

    public void setSortname(String sortname) {
        this.sortname = sortname;
    }

    @Override
    public String toString() {
        return "PagingEntity{" +
                "page=" + page +
                ", rp=" + rp +
                ", start=" + start +
                ", sortorder='" + sortorder + '\'' +
                ", sortname='" + sortname + '\'' +
                '}';
    }

    public  void dealColums(Class<?>tclass){
        if( "".equals(this.sortname) ||"undefined".equals(this.sortname) ){
            return;
        }
        Field field = null;
        try {
           field = tclass.getDeclaredField(this.sortname);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
            return;
        }
        if(field.isAnnotationPresent(Colums.class)){
          Colums colums = field.getAnnotation(Colums.class);
          this.sortname = colums.value();
        }
    }

    public void dealColumns(Class<PtFileEntity> ptFileEntityClass) {
    }
}
